﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using ERP_RORZE_SYSTEM;
using System.Data.OleDb;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERP_RORZE_DLL.Assembly
{
    public partial class panel_F4CheckFORS300 : UserControl
    {
        private INISettings mySetting;
        private SqlConnection myConnection;
        public panel_F4CheckFORS300()
        {
            InitializeComponent();
            mySetting = new INISettings();
            myConnection = new SqlConnection(mySetting.SQLConnectionString);
            LoadData();
            this.RV201.DoubleClick += RV201_DoubleClick;
            this.RV201.PopupMenuShowing += RV201_PopupMenuShowing;
            this.f4RV201ContextMenu.ItemClicked += f4RV201ContextMenu_ItemClicked;
        }

        /////////////////////////////
        /// Call Edit Form
        /////////////////////////////
        private void callEditForm()
        {
            DataRow row = RV201.GetFocusedDataRow();
            frm_Edit_F4CheckFORS300 editForm = new frm_Edit_F4CheckFORS300();
            editForm.serial = row[2].ToString();
            if (editForm.LoadData())
            {
                editForm.ShowDialog();
                //LoadData();
            }
            else
            {
                MessageBox.Show("Cannot edit selected row.");
            }
        }

        void f4RV201ContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            this.f4RV201ContextMenu.Hide();            
            switch (e.ClickedItem.Name)
            {
                case "editSelection":
                    callEditForm();
                    break;
                case "addSelection":
                    frm_Add_F4CheckFORS300 add_Form = new frm_Add_F4CheckFORS300();
                    add_Form.ShowDialog();
                    //LoadData();
                    break;                
                case "refreshSelection":
                    LoadData();
                    break;
            }
        }

        void RV201_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
        {
            this.f4RV201ContextMenu.Show(MousePosition);
        }

        private void RV201_DoubleClick(object sender, EventArgs e)
        {
            callEditForm();                        
        }
        
        //////////////////////////////////////////////////
        /// Load data from database to grid
        //////////////////////////////////////////////////
        private void LoadData()
        {
            DataSet sourceDataSet = new DataSet();
            SQLManagement mySQLManagement = new SQLManagement();
            mySQLManagement.SQLConnectionString = mySetting.SQLConnectionString;
            string sql = "SELECT SUBSTRING(t1.[SerialNo],1,7) as SerialRJ, t2.[CompID], t1.[SerialNo],"
                        + " t1.[Written], t1.[Date], ISNULL(t1.[Checked], '***') AS Checked,"
                        + " ISNULL(t1.[WiringDaiagram], '**') AS WiringDaiagram, ISNULL(t1.[Running], '***') AS Running,"
                        + " ISNULL(t1.Y, '***') AS Y, ISNULL(t1.Z, '***') AS Z, ISNULL(t1.[PCPower], '***') AS PCPower,"
                        + " ISNULL(t1.[PCPowerSerial], '***') AS PCPowerSerial, ISNULL(t1.[RC420_1], '***') AS RC420_1,"
                        + " ISNULL(t1.[RC420_1_Ver], '***') AS RC420_1_Ver, ISNULL(t1.[RC420_1_Ex_Ver], '***') AS RC420_1_Ex_Ver,"
                        + " t1.[RC420_2], t1.[RC420_2_Ver], ISNULL(t1.[RC420_2_Ex_Ver], '***') AS RC420_2_Ex_Ver,"
                        + " ISNULL(t1.[RC410_3], '***') AS RC410_3, ISNULL(t1.[RC410_3_Ver], '***') AS RC410_3_Ver,"
                        + " ISNULL(t1.[RC410_4], '***') AS RC410_4, ISNULL(t1.[RC410_4_Ver], '***') AS RC410_4_Ver,"
                        + " ISNULL(t1.[RC410_5], '***') AS RC410_5, ISNULL(t1.[RC410_5_Ver], '***') AS RC410_5_Ver,"
                        + " ISNULL(t1.[RC410_6], '***') AS RC410_6, ISNULL(t1.[RC410_6_Ver], '***') AS RC410_6_Ver,"
                        + " ISNULL(t1.[RD023_Y], '***') AS RD023_Y, ISNULL(CAST(t1.[Y_Run] AS VARCHAR), '***') AS Y_Run,"
                        + " ISNULL(CAST(t1.[Y_Stop] AS VARCHAR), '***') AS Y_Stop, ISNULL(t1.[RD023_Z], '***') AS RD023_Z,"
                        + " ISNULL(CAST(t1.[Z_Run] AS VARCHAR), '***') AS Z_Run, ISNULL(CAST(t1.[Z_Stop] AS VARCHAR), '***') AS Z_Stop,"
                        + " t1.[Y_OH], t1.[Y_OL], t1.[Y_QI], t1.[Y_OA], t1.[Y_OB], t1.[Y_OS], t1.[Y_0S], t1.[Z_OH],"
                        + " t1.[Z_OL], t1.[Z_QI], t1.[Z_OA], t1.[Z_OB], t1.[Z_OS], t1.[Z_0S], t1.[Y1], t1.[Y2], t1.[Y3],"
                        + " t1.[Y4], t1.[Y5], t1.[Y6], t1.[Z1], t1.[Z2], t1.[Z3], t1.[Z4], t1.[Z5], t1.[Z6],"
                        + " ISNULL(t1.[Remark], '***') AS Remark, t1.[a35], t1.[b35], t1.[c35], t1.[d35], t1.[A],"
                        + " t1.[/A], t1.[B], t1.[/B], t1.[C], t1.[/C], t1.[D], t1.[/D], t1.[E], t1.[/E], t1.[F], t1.[/F],"
                        + " t1.[G], t1.[/G], t1.[H], t1.[/H], ISNULL(t1.[PC_Board], '***') AS PC_Board,"
                        + " ISNULL(t1.[BCR], '***') AS BCR, t2.[ExportedDate], t2.[CustomerID], t1.[Foup], t1.[Fosb], t1.[OC25],"
                        + " t1.[OC13], t1.[Foup Slot Num], t1.[Foup Slot Pitch], t1.[Foup Min Thickness], t1.[Foup Max Thickness],"
                        + " t1.[Foup Offset], t1.[Foup Bow], t1.[Fosb Slot Num], t1.[Fosb Slot Pitch], t1.[Fosb Min Thickness],"
                        + " t1.[Fosb Max Thickness], t1.[Fosb Offset], t1.[Fosb Bow], t1.[OC25 Slot Num], t1.[OC25 Slot Pitch],"
                        + " t1.[OC25 Min Thickness], t1.[OC25 Max Thickness], t1.[OC25 Offset], t1.[OC25 Bow],"
                        + " t1.[OC13 Slot Num], t1.[OC13 Slot Pitch], t1.[OC13 Min Thickness], t1.[OC13 Max Thickness],"
                        + " t1.[OC13 Offset], t1.[OC13 Bow], t1.[Top], t1.[Bottom], t1.[Ver], ISNULL(t1.[Host name], '***') AS [Host name],"
                        + " ISNULL(t1.[Host IP Adrs], '***') AS [Host IP Adrs], ISNULL(CAST(t1.[Body No] AS VARCHAR), '***') AS [Body No],"
                        + " t1.[OS when Pod Unload], t1.[Timer(Pod Clamp/Rotate)], t1.[Timer(Lock Key)], t1.[Timer(Mapper Move)],"
                        + " t1.[Timer(Vacuum)], t1.[OS when SUndock], t1.[Wait for mapping], t1.[OA when SUndock],"
                        + " t1.[Timer(Placement)], t1.[Timer(Presence)], t1.[Pulse Vacuum Retry], t1.[Default Map],"
                        + " t1.[Timer(BCR)], t1.[Timer(PRS)], t1.[Timer(Rotation)], t1.[IP_Adress],"
                        + " ISNULL(t1.[BCR data], '***') AS [BCR data], t1.[Host Port], ISNULL(t1.[CF Image], '***') AS [CF Image],"
                        + " ISNULL(t1.[Appearance Diagram], '***') AS [Appearance Diagram],"
                        + " ISNULL(CAST(t1.[Mapper Threshold] AS VARCHAR), '***') AS [Mapper Threshold],"
                        + " ISNULL(t1.[Stacker Hand Threshold], '***') AS [Stacker Hand Threshold],"
                        + " ISNULL(t1.[Laser Prt Threshold], '***') AS [Laser Prt Threshold]"
                        + " FROM [231_F4RV201] AS t1 LEFT JOIN"
                        + " [231_RobotOrderDetail] AS t2 ON t1.[SerialNo] COLLATE Vietnamese_CI_AS=t2.[SerialNo]";
            sourceDataSet = mySQLManagement.SQL_Query(sql);

            if (sourceDataSet != null)
            {
                DataTable ShowTable = sourceDataSet.Tables[0].Clone();
                for (int i = 0; i < ShowTable.Columns.Count; i++)
                {
                    ShowTable.Columns[i].DataType = typeof(string);
                }
                foreach (DataRow check_row in sourceDataSet.Tables[0].Rows)
                {
                    ShowTable.ImportRow(check_row);                    
                }

                foreach (DataRow show_row in ShowTable.Rows)
                {                    
                    show_row.BeginEdit();
                    for (int i = 0; i < sourceDataSet.Tables[0].Columns.Count; i++)
                    {
                        if (string.IsNullOrEmpty(show_row[i].ToString().Trim()))
                        {
                            show_row[i] = "***";
                        }
                    }
                    show_row.EndEdit();
                }
                gridRV201.DataSource = ShowTable;
            }
            else
            {
                DataTable newTable = new DataTable();
                newTable.Columns.Add("Serial No(RJ)", typeof(string));
                newTable.Columns.Add("Comp no", typeof(string));
                newTable.Columns.Add("Serial No", typeof(string));
                newTable.Columns.Add("Written", typeof(string));
                newTable.Columns.Add("Date", typeof(string));
                newTable.Columns.Add("Checked", typeof(string));
                newTable.Columns.Add("Wiring Daiagram", typeof(string));
                newTable.Columns.Add("Running", typeof(string));
                newTable.Columns.Add("Y", typeof(string));
                newTable.Columns.Add("Z", typeof(string));
                newTable.Columns.Add("PC Power", typeof(string));
                newTable.Columns.Add("PC Power Serial", typeof(string));
                newTable.Columns.Add("RC420-1", typeof(string));
                newTable.Columns.Add("RC420-1 Ver", typeof(string));
                newTable.Columns.Add("RC420-1 Ex ver", typeof(string));
                newTable.Columns.Add("RC420-2", typeof(string));
                newTable.Columns.Add("RC420-2 Ver", typeof(string));
                newTable.Columns.Add("RC420-2 Ex ver", typeof(string));
                newTable.Columns.Add("RC410-3", typeof(string));
                newTable.Columns.Add("RC410-3 Ver", typeof(string));
                newTable.Columns.Add("RC410-4", typeof(string));
                newTable.Columns.Add("RC410-4 Ver", typeof(string));
                newTable.Columns.Add("RC410-5", typeof(string));
                newTable.Columns.Add("RC410-5 Ver", typeof(string));
                newTable.Columns.Add("RC410-6", typeof(string));
                newTable.Columns.Add("RC410-6 Ver", typeof(string));
                newTable.Columns.Add("RD023-Y", typeof(string));
                newTable.Columns.Add("Y-Run", typeof(string));
                newTable.Columns.Add("Y-Stop", typeof(string));
                newTable.Columns.Add("RD023-Z", typeof(string));
                newTable.Columns.Add("Z-Run", typeof(string));
                newTable.Columns.Add("Z-Stop", typeof(string));
                newTable.Columns.Add("Y-OH", typeof(string));
                newTable.Columns.Add("Y-OL", typeof(string));
                newTable.Columns.Add("Y-QI", typeof(string));
                newTable.Columns.Add("Y-OA", typeof(string));
                newTable.Columns.Add("Y-OB", typeof(string));
                newTable.Columns.Add("Y-OS", typeof(string));
                newTable.Columns.Add("Y-0S", typeof(string));
                newTable.Columns.Add("Z-OH", typeof(string));
                newTable.Columns.Add("Z-OL", typeof(string));
                newTable.Columns.Add("Z-QI", typeof(string));
                newTable.Columns.Add("Z-OA", typeof(string));
                newTable.Columns.Add("Z-OB", typeof(string));
                newTable.Columns.Add("Z-OS", typeof(string));
                newTable.Columns.Add("Z-0S", typeof(string));
                newTable.Columns.Add("Y1", typeof(string));
                newTable.Columns.Add("Y2", typeof(string));
                newTable.Columns.Add("Y3", typeof(string));
                newTable.Columns.Add("Y4", typeof(string));
                newTable.Columns.Add("Y5", typeof(string));
                newTable.Columns.Add("Y6", typeof(string));
                newTable.Columns.Add("Z1", typeof(string));
                newTable.Columns.Add("Z2", typeof(string));
                newTable.Columns.Add("Z3", typeof(string));
                newTable.Columns.Add("Z4", typeof(string));
                newTable.Columns.Add("Z5", typeof(string));
                newTable.Columns.Add("Z6", typeof(string));
                newTable.Columns.Add("Remark", typeof(string));
                newTable.Columns.Add("a35", typeof(string));
                newTable.Columns.Add("b35", typeof(string));
                newTable.Columns.Add("c35", typeof(string));
                newTable.Columns.Add("d35", typeof(string));
                newTable.Columns.Add("A", typeof(string));
                newTable.Columns.Add("/A", typeof(string));
                newTable.Columns.Add("B", typeof(string));
                newTable.Columns.Add("/B", typeof(string));
                newTable.Columns.Add("C", typeof(string));
                newTable.Columns.Add("/C", typeof(string));
                newTable.Columns.Add("D", typeof(string));
                newTable.Columns.Add("/D", typeof(string));
                newTable.Columns.Add("E", typeof(string));
                newTable.Columns.Add("/E", typeof(string));
                newTable.Columns.Add("F", typeof(string));
                newTable.Columns.Add("/F", typeof(string));
                newTable.Columns.Add("G", typeof(string));
                newTable.Columns.Add("/G", typeof(string));
                newTable.Columns.Add("H", typeof(string));
                newTable.Columns.Add("/H", typeof(string));
                newTable.Columns.Add("PC_Board", typeof(string));
                newTable.Columns.Add("BCR", typeof(string));
                newTable.Columns.Add("ExportedDate", typeof(string));
                newTable.Columns.Add("CustomerID", typeof(string));
                newTable.Columns.Add("Foup", typeof(string));
                newTable.Columns.Add("Fosb", typeof(string));
                newTable.Columns.Add("OC25", typeof(string));
                newTable.Columns.Add("OC13", typeof(string));
                newTable.Columns.Add("Foup Slot Num", typeof(string));
                newTable.Columns.Add("Foup Slot Pitch", typeof(string));
                newTable.Columns.Add("Foup Min Thickness", typeof(string));
                newTable.Columns.Add("Foup Max Thickness", typeof(string));
                newTable.Columns.Add("Foup Offset", typeof(string));
                newTable.Columns.Add("Foup Bow", typeof(string));
                newTable.Columns.Add("Fosb Slot Num", typeof(string));
                newTable.Columns.Add("Fosb Slot Pitch", typeof(string));
                newTable.Columns.Add("Fosb Min Thickness", typeof(string));
                newTable.Columns.Add("Fosb Max Thickness", typeof(string));
                newTable.Columns.Add("Fosb Offset", typeof(string));
                newTable.Columns.Add("Fosb Bow", typeof(string));
                newTable.Columns.Add("OC25 Slot Num", typeof(string));
                newTable.Columns.Add("OC25 Slot Pitch", typeof(string));
                newTable.Columns.Add("OC25 Min Thickness", typeof(string));
                newTable.Columns.Add("OC25 Max Thickness", typeof(string));
                newTable.Columns.Add("OC25 Offset", typeof(string));
                newTable.Columns.Add("OC25 Bow", typeof(string));
                newTable.Columns.Add("OC13 Slot Num", typeof(string));
                newTable.Columns.Add("OC13 Slot Pitch", typeof(string));
                newTable.Columns.Add("OC13 Min Thickness", typeof(string));
                newTable.Columns.Add("OC13 Max Thickness", typeof(string));
                newTable.Columns.Add("OC13 Offset", typeof(string));
                newTable.Columns.Add("OC13 Bow", typeof(string));
                newTable.Columns.Add("Top", typeof(string));
                newTable.Columns.Add("Bottom", typeof(string));
                newTable.Columns.Add("Ver", typeof(string));
                newTable.Columns.Add("Host name", typeof(string));
                newTable.Columns.Add("Host IP Adrs", typeof(string));
                newTable.Columns.Add("Body No", typeof(string));
                newTable.Columns.Add("OS when Pod Unload", typeof(string));
                newTable.Columns.Add("Timer(Pod Clamp/Rotate)", typeof(string));
                newTable.Columns.Add("Timer(Lock Key)", typeof(string));
                newTable.Columns.Add("Timer(Mapper Move)", typeof(string));
                newTable.Columns.Add("Timer(Vacuum)", typeof(string));
                newTable.Columns.Add("OS when SUndock", typeof(string));
                newTable.Columns.Add("Wait for mapping", typeof(string));
                newTable.Columns.Add("OA when SUndock", typeof(string));
                newTable.Columns.Add("Timer(Placement)", typeof(string));
                newTable.Columns.Add("Timer(Presence)", typeof(string));
                newTable.Columns.Add("Pulse Vacuum Retry", typeof(string));
                newTable.Columns.Add("Default Map", typeof(string));
                newTable.Columns.Add("Timer(BCR)", typeof(string));
                newTable.Columns.Add("Timer(PRS)", typeof(string));
                newTable.Columns.Add("Timer(Rotation)", typeof(string));
                newTable.Columns.Add("IP_Adress", typeof(string));
                newTable.Columns.Add("BCR data", typeof(string));
                newTable.Columns.Add("Host Port", typeof(string));
                newTable.Columns.Add("CF Image", typeof(string));
                newTable.Columns.Add("Appearance Diagram", typeof(string));
                newTable.Columns.Add("Mapper Threshold", typeof(string));
                newTable.Columns.Add("Stacker Hand Threshold", typeof(string));
                newTable.Columns.Add("Laser Prt. Threshold", typeof(string));

                gridRV201.DataSource = newTable;
            }
            RV201.Columns[0].Caption = "Serial No(RJ):";
            RV201.Columns[1].Caption = "Comp no:";
            RV201.Columns[2].Caption = "Serial No:";
            RV201.Columns[3].Caption = "Written:";
            RV201.Columns[4].Caption = "Date:";
            RV201.Columns[4].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            RV201.Columns[4].DisplayFormat.FormatString = "yyyy/MM/dd";
            RV201.Columns[5].Caption = "Checked:";
            RV201.Columns[6].Caption = "Wiring Daiagram:";
            RV201.Columns[7].Caption = "Running:";
            RV201.Columns[8].Caption = "Y:";
            RV201.Columns[9].Caption = "Z:";
            RV201.Columns[10].Caption = "PC Power:";
            RV201.Columns[11].Caption = "PC Power Serial:";
            RV201.Columns[12].Caption = "RC420-1:";
            RV201.Columns[13].Caption = "RC420-1 Ver:";
            RV201.Columns[14].Caption = "RC420-1 Ex ver:";
            RV201.Columns[15].Caption = "RC420-2:";
            RV201.Columns[16].Caption = "RC420-2 Ver:";
            RV201.Columns[17].Caption = "RC420-2 Ex ver:";
            RV201.Columns[18].Caption = "RC410-3:";
            RV201.Columns[19].Caption = "RC410-3 Ver:";
            RV201.Columns[20].Caption = "RC410-4:";
            RV201.Columns[21].Caption = "RC410-4 Ver:";
            RV201.Columns[22].Caption = "RC410-5:";
            RV201.Columns[23].Caption = "RC410-5 Ver:";
            RV201.Columns[24].Caption = "RC410-6:";
            RV201.Columns[25].Caption = "RC410-6 Ver:";
            RV201.Columns[26].Caption = "RD023-Y:";
            RV201.Columns[27].Caption = "Y-Run:";
            RV201.Columns[28].Caption = "Y-Stop:";
            RV201.Columns[29].Caption = "RD023-Z:";
            RV201.Columns[30].Caption = "Z-Run:";
            RV201.Columns[31].Caption = "Z-Stop:";
            RV201.Columns[32].Caption = "Y-OH:";
            RV201.Columns[33].Caption = "Y-OL:";
            RV201.Columns[34].Caption = "Y-QI:";
            RV201.Columns[35].Caption = "Y-OA:";
            RV201.Columns[36].Caption = "Y-OB:";
            RV201.Columns[37].Caption = "Y-OS:";
            RV201.Columns[38].Caption = "Y-0S:";
            RV201.Columns[39].Caption = "Z-OH:";
            RV201.Columns[40].Caption = "Z-OL:";
            RV201.Columns[41].Caption = "Z-QI:";
            RV201.Columns[42].Caption = "Z-OA:";
            RV201.Columns[43].Caption = "Z-OB:";
            RV201.Columns[44].Caption = "Z-OS:";
            RV201.Columns[45].Caption = "Z-0S:";
            RV201.Columns[46].Caption = "Y1:";
            RV201.Columns[47].Caption = "Y2:";
            RV201.Columns[48].Caption = "Y3:";
            RV201.Columns[49].Caption = "Y4:";
            RV201.Columns[50].Caption = "Y5:";
            RV201.Columns[51].Caption = "Y6:";
            RV201.Columns[52].Caption = "Z1:";
            RV201.Columns[53].Caption = "Z2:";
            RV201.Columns[54].Caption = "Z3:";
            RV201.Columns[55].Caption = "Z4:";
            RV201.Columns[56].Caption = "Z5:";
            RV201.Columns[57].Caption = "Z6:";
            RV201.Columns[58].Caption = "Remark:";
            RV201.Columns[59].Caption = "a35:";
            RV201.Columns[60].Caption = "b35:";
            RV201.Columns[61].Caption = "c35:";
            RV201.Columns[62].Caption = "d35:";
            RV201.Columns[63].Caption = "A:";
            RV201.Columns[64].Caption = "/A:";
            RV201.Columns[65].Caption = "B:";
            RV201.Columns[66].Caption = "/B:";
            RV201.Columns[67].Caption = "C:";
            RV201.Columns[68].Caption = "/C:";
            RV201.Columns[69].Caption = "D:";
            RV201.Columns[70].Caption = "/D:";
            RV201.Columns[71].Caption = "E:";
            RV201.Columns[72].Caption = "/E:";
            RV201.Columns[73].Caption = "F:";
            RV201.Columns[74].Caption = "/F:";
            RV201.Columns[75].Caption = "G:";
            RV201.Columns[76].Caption = "/G:";
            RV201.Columns[77].Caption = "H:";
            RV201.Columns[78].Caption = "/H:";
            RV201.Columns[79].Caption = "PC_Board:";
            RV201.Columns[80].Caption = "BCR:";
            RV201.Columns[81].Caption = "ExportedDate:";
            RV201.Columns[81].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            RV201.Columns[81].DisplayFormat.FormatString = "yyyy/MM/dd";
            RV201.Columns[82].Caption = "CustomerID:";
            RV201.Columns[83].Caption = "Foup:";
            RV201.Columns[84].Caption = "Fosb:";
            RV201.Columns[85].Caption = "OC25:";
            RV201.Columns[86].Caption = "OC13:";
            RV201.Columns[87].Caption = "Foup Slot Num:";
            RV201.Columns[88].Caption = "Foup Slot Pitch:";
            RV201.Columns[89].Caption = "Foup Min Thickness:";
            RV201.Columns[90].Caption = "Foup Max Thickness:";
            RV201.Columns[91].Caption = "Foup Offset:";
            RV201.Columns[92].Caption = "Foup Bow:";
            RV201.Columns[93].Caption = "Fosb Slot Num:";
            RV201.Columns[94].Caption = "Fosb Slot Pitch:";
            RV201.Columns[95].Caption = "Fosb Min Thickness:";
            RV201.Columns[96].Caption = "Fosb Max Thickness:";
            RV201.Columns[97].Caption = "Fosb Offset:";
            RV201.Columns[98].Caption = "Fosb Bow:";
            RV201.Columns[99].Caption = "OC25 Slot Num:";
            RV201.Columns[100].Caption = "OC25 Slot Pitch:";
            RV201.Columns[101].Caption = "OC25 Min Thickness:";
            RV201.Columns[102].Caption = "OC25 Max Thickness:";
            RV201.Columns[103].Caption = "OC25 Offset:";
            RV201.Columns[104].Caption = "OC25 Bow:";
            RV201.Columns[105].Caption = "OC13 Slot Num:";
            RV201.Columns[106].Caption = "OC13 Slot Pitch:";
            RV201.Columns[107].Caption = "OC13 Min Thickness:";
            RV201.Columns[108].Caption = "OC13 Max Thickness:";
            RV201.Columns[109].Caption = "OC13 Offset:";
            RV201.Columns[110].Caption = "OC13 Bow:";
            RV201.Columns[111].Caption = "Top:";
            RV201.Columns[112].Caption = "Bottom:";
            RV201.Columns[113].Caption = "Ver:";
            RV201.Columns[114].Caption = "Host name:";
            RV201.Columns[115].Caption = "Host IP Adrs:";
            RV201.Columns[116].Caption = "Body No:";
            RV201.Columns[117].Caption = "OS when Pod Unload:";
            RV201.Columns[118].Caption = "Timer(Pod Clamp/Rotate):";
            RV201.Columns[119].Caption = "Timer(Lock Key):";
            RV201.Columns[120].Caption = "Timer(Mapper Move):";
            RV201.Columns[121].Caption = "Timer(Vacuum):";
            RV201.Columns[122].Caption = "OS when SUndock:";
            RV201.Columns[123].Caption = "Wait for mapping:";
            RV201.Columns[124].Caption = "OA when SUndock:";
            RV201.Columns[125].Caption = "Timer(Placement):";
            RV201.Columns[126].Caption = "Timer(Presence):";
            RV201.Columns[127].Caption = "Pulse Vacuum Retry:";
            RV201.Columns[128].Caption = "Default Map:";
            RV201.Columns[129].Caption = "Timer(BCR):";
            RV201.Columns[130].Caption = "Timer(PRS):";
            RV201.Columns[131].Caption = "Timer(Rotation):";
            RV201.Columns[132].Caption = "IP_Adress:";
            RV201.Columns[133].Caption = "BCR data:";
            RV201.Columns[134].Caption = "Host Port:";
            RV201.Columns[135].Caption = "CF Image:";
            RV201.Columns[136].Caption = "Appearance Diagram:";
            RV201.Columns[137].Caption = "Mapper Threshold:";
            RV201.Columns[138].Caption = "Stacker Hand Threshold:";
            RV201.Columns[139].Caption = "Laser Prt. Threshold:";

            RV201.BestFitColumns();

        }

        private void bottonAdd_Click(object sender, EventArgs e)
        {
            frm_Add_F4CheckFORS300 add_Form = new frm_Add_F4CheckFORS300();
            add_Form.ShowDialog();
            //LoadData();
        }

        private void bottonEdit_Click(object sender, EventArgs e)
        {
            callEditForm();
        }

        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            LoadData();
        }

        private void buttonExport_Click(object sender, EventArgs e)
        {
            Cursor currentCursor = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                SaveFileDialog saveFDlg = new SaveFileDialog();
                saveFDlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                saveFDlg.Filter = "Microsoft Office Excel|*.xlsx";
                saveFDlg.Title = "Save As";
                saveFDlg.FileName = "RV201F05.xlsx";
                if (saveFDlg.ShowDialog(this) == DialogResult.OK)
                {
                    if (!string.IsNullOrEmpty(saveFDlg.FileName))
                    {
                        RV201.OptionsPrint.PrintDetails = true;
                        RV201.OptionsPrint.ExpandAllDetails = true;
                        RV201.OptionsPrint.AutoWidth = false;
                        DevExpress.XtraPrinting.XlsxExportOptions myOptions = new DevExpress.XtraPrinting.XlsxExportOptions();                        
                        myOptions.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text;
                        myOptions.ShowGridLines = true;
                        RV201.ExportToXlsx(saveFDlg.FileName, myOptions);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Warning!");
            }
            finally
            {
                Cursor.Current = currentCursor;
            }
        }
    }
}
